package lxx.pandams.activity;

import lxx.panda.util.ServiceUtil;
import lxx.pandams.R;
import lxx.pandams.service.BlackNumberService;
import lxx.pandams.view.SettingItemView;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;

public class SettingActivity extends Activity{
	
	private Context ctx;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_setting);
		ctx = this;
		initUI();
		initData();
		initBlacknumber();
	}
	
	//initialize some views in this layout 
	private void initUI() {
		
	}

	//set some actions or data for views
	private void initData() {
		
	}
	
	private void initBlacknumber() {
		final SettingItemView siv_blacknumber = (SettingItemView) findViewById(R.id.siv_blacknumber);
		boolean isRunning = ServiceUtil.isRunning(this, "lxx.pandams.service.BlackNumberService");
		siv_blacknumber.setCheck(isRunning);
		
		siv_blacknumber.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				boolean isCheck = siv_blacknumber.isCheck();
				siv_blacknumber.setCheck(!isCheck);
				if(!isCheck){
					//开启服务
					startService(new Intent(getApplicationContext(), BlackNumberService.class));
				}else{
					//关闭服务
					stopService(new Intent(getApplicationContext(), BlackNumberService.class));
				}
			}
		});
	}
}
